package Q4;

import java.util.Scanner;

public class Question4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 输入系统空闲资源数Available
        int[] available = new int[3];
        for (int i = 0; i < 3; i++) {
            available[i] = scanner.nextInt();
        }
        scanner.nextLine(); // 读取行结束符

        String[][] processInfo = new String[5][7];
        int[][] claim = new int[5][3];
        int[][] allocation = new int[5][3];

        // 输入每个进程的资源信息
        for (int i = 0; i < 5; i++) {
            String line = scanner.nextLine();
            processInfo[i] = line.split(" ");
            claim[i][0] = Integer.parseInt(processInfo[i][1]);
            claim[i][1] = Integer.parseInt(processInfo[i][2]);
            claim[i][2] = Integer.parseInt(processInfo[i][3]);
            allocation[i][0] = Integer.parseInt(processInfo[i][4]);
            allocation[i][1] = Integer.parseInt(processInfo[i][5]);
            allocation[i][2] = Integer.parseInt(processInfo[i][6]);
        }

        // 计算总资源Resource
        int[] totalResources = new int[3];
        for (int i = 0; i < 3; i++) {
            totalResources[i] = available[i];
            for (int j = 0; j < 5; j++) {
                totalResources[i] += allocation[j][i];
            }
        }

        // 打印系统的总资源
        System.out.println(totalResources[0] + " " + totalResources[1] + " " + totalResources[2]);

        // 计算需求矩阵Need
        for (int i = 0; i < 5; i++) {
            System.out.print(processInfo[i][0] + " "); // 进程名
            int needA = claim[i][0] - allocation[i][0];
            int needB = claim[i][1] - allocation[i][1];
            int needC = claim[i][2] - allocation[i][2];
            System.out.println(needA + " " + needB + " " + needC);
        }

        scanner.close();
    }
}